

let dTime = 'date_time';

function put(k, v, t) {
  my.setStorageSync({ key: k, data: v })
  let key = k + dTime
  let seconds = parseInt(t);
  if (seconds > 0) {
    let timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000 + seconds;
    timestamp = timestamp + ""
    my.setStorageSync({ key: key, data: timestamp })
  } else {

    my.removeStorageSync({ key: key });
  }
}

function get(k, def) {
  let key = k + dTime
  let dateTime = my.getStorageSync({ key: key })
  dateTime = parseInt(dateTime.data)
  if (dateTime) {
    if (dateTime < Date.parse(new Date()) / 1000) {
      if (def) {
        return def;
      } else {
        return;
      }
    }
  }
  let res = my.getStorageSync({ key: k, });
  if (res) {
    return res.data;
  } else {
    return def;
  }
}

function remove(k) {
  my.removeStorageSync({ key: k, });
  let key = k + dTime
  my.removeStorageSync({ key: key });
}

function clear() {
  my.clearStorageSync();
}


module.exports = {
  put: put,
  get: get,
  remove: remove,
  clear: clear,
}
